<template>
  <div>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <el-table-column :show-overflow-tooltip="true" prop="contractCode" label="合同编号" />
      <el-table-column :show-overflow-tooltip="true" prop="contractName" label="合同名称" />
      <!--
      <el-table-column :show-overflow-tooltip="true" prop="customerName" label="所属客户" />
      -->
      <el-table-column :show-overflow-tooltip="true" prop="contractItemName" label="合同类型" />
      <el-table-column :show-overflow-tooltip="true" prop="startTime" label="合同开始时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="endTime" label="合同结束时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>
      <!--
      <el-table-column :show-overflow-tooltip="true" prop="contractMoney" label="合同金额" />
      -->
      <el-table-column v-if="checkPermission(['ADMIN','TCUSTOMERCONTRACT_ALL','TCUSTOMERCONTRACT_EDIT','TCUSTOMERCONTRACT_DELETE'])" label="操作" width="80px" align="center">
        <template slot-scope="scope">
          <edit v-permission="['ADMIN','TCUSTOMERINFO_ALL','TCUSTOMERINFO_EDIT']" :data="scope.row" :sup-this.sync="supThis" :is-view="true" :is-add="false" />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { parseTime } from '@/utils/index'
import edit from '@/views/customer/customercontract/module/edit'

export default {
  components: {
    edit
  },
  mixins: [initData],
  data() {
    return {
      supThis: this
    }
  },
  methods: {
    checkPermission,
    parseTime,
    beforeInit() {
      this.url = 'api/tCustomerContract'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      // const type = query.type
      // const value = query.value
      // if (type && value) { this.params[type] = value }
      if (query.contractCode) {
        this.params['contractCode'] = query.contractCode
      }
      if (query.contractName) {
        this.params['contractName'] = query.contractName
      }
      if (query.customerName) {
        this.params['customerName'] = query.customerName
      }
      if (query.contractItemName) {
        this.params['contractItemName'] = query.contractItemName
      }
      return true
    },
    search({ customerName }) {
      this.query.customerName = customerName
      this.init()
    }
  }
}
</script>
